<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('申请开票列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>发票类型：</label>
                            <select name="invoiceType" th:with="type=${@dict.getType('work_invoice_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>发票抬头：</label>
                            <input type="text" name="invoiceTitle"/>
                        </li>
                        <li>
                            <label>开票人：</label>
                            <input type="text" name="belong"/>
                        </li>
                        <li>
                            <label>客户名称：</label>
                            <input type="text" name="customerName"/>
                        </li>
                        <li>
                            <label>开哪个公司：</label>

                            <select name="invoiceCompany" class="form-control m-b" th:with="type=${@dict.getType('work_invoice_company')}" required>
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>

                        <li>
                            <label>合同：</label>

                            <select name="isContract" class="form-control m-b" th:with="type=${@dict.getType('work_yes_no')}" required>
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>开票内容：</label>
                            <input type="text" name="invoiceContent"/>
                        </li>

                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="work:invoice:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="work:invoice:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
<!--            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="work:invoice:remove">
                <i class="fa fa-remove"></i> 删除
            </a>-->
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="work:invoice:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-primary" onclick="check()" shiro:hasPermission="work:invoice:check">
                <i class="fa fa-gavel"></i> 审核
            </a>
            <a class="btn btn-primary" onclick="grant()" shiro:hasPermission="work:invoice:grant">
                <i class="fa fa-money"></i> 开票
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table" class="table text-nowrap"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('work:invoice:edit')}]];
    var removeFlag = [[${@permission.hasPermi('work:invoice:remove')}]];
    var invoiceTypeDatas = [[${@dict.getType('work_invoice_type')}]];
    var invoiceCompanyDatas = [[${@dict.getType('work_invoice_company')}]];
    var bankNoDatas = [[${@dict.getType('work_bank')}]];
    var isContractDatas = [[${@dict.getType('work_yes_no')}]];
    var paperTypeDatas = [[${@dict.getType('work_paper_type')}]];
    var platformDatas = [[${@dict.getType('work_platform')}]];
    var priceTypeDatas = [[${@dict.getType('work_price_type')}]];
    var paperStatusDatas = [[${@dict.getType('work_paper_status')}]];
    var prefix = ctx + "work/invoice";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "申请开票",
            detailView: true,
            onExpandRow : function(index, row, $detail) {
                initChildTable(index, row, $detail);
            },
            columns: [{
                checkbox: true
            },
                {
                    field: 'invoiceId',
                    title: '发票ID',
                    align: 'center'
                },
                {
                    field: 'invoiceType',
                    title: '发票类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(invoiceTypeDatas, value);
                    },
                    align: 'center'
                },
                {
                    field: 'belong',
                    title: '开票人',
                    align: 'center'
                },
                {
                    field: 'invoiceTitle',
                    title: '发票抬头',
                    align: 'center'
                },
                {
                    field: 'customerName',
                    title: '客户名称',
                    align: 'center'
                },
                {
                    field: 'invoiceCompany',
                    title: '开哪个公司',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(invoiceCompanyDatas, value);
                    },
                    align: 'center'
                },
                {
                    field: 'invoiceContent',
                    title: '开票内容',
                    align: 'center'
                },
                {
                    field: 'invoicePrice',
                    title: '开票金额',
                    align: 'center'
                },
                {
                    field: 'paperPrice',
                    title: '已选稿件金额',
                    align: 'center'
                },
                {
                    field: 'taxPoint',
                    title: '税点',
                    align: 'center'
                },
                {
                    field: '',
                    title: '税金',
                    formatter: function (value, row, index) {
                        return row.invoicePrice * row.taxPoint / 100;
                    },
                    align: 'center'
                },
                {
                    field: 'taxPoint',
                    title: '价税合计',
                    formatter: function (value, row, index) {
                        return row.invoicePrice+(row.invoicePrice * row.taxPoint / 100);
                    },
                    align: 'center'
                },
                {
                    field: 'payback',
                    title: '客户还款',
                    align: 'center'
                },
                {
                    field: 'taxNo',
                    title: '税务登记证号',
                    align: 'center'
                },
                {
                    field: 'bankNo',
                    title: '基本开户银行',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(bankNoDatas, value);
                    },
                    align: 'center'
                },
                {
                    field: 'bankAccount',
                    title: '开户银行账号',
                    align: 'center'
                },
                {
                    field: 'isContract',
                    title: '合同',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(isContractDatas, value);
                    },
                    align: 'center'
                },
                {
                    field: 'contractDate',
                    title: '合同收集日期',
                    align: 'center'
                },
                {
                    field: 'registerAddress',
                    title: '注册场所地址',
                    align: 'center'
                },
                {
                    field: 'registerTel',
                    title: '注册场所电话',
                    align: 'center'
                },
                {
                    field: 'uploadFile',
                    title: '凭证',
                    formatter: function (value, row, index) {
                        if (value != '' && value != undefined) {
                            var fileName = value.substr(value.lastIndexOf("/")+1);
                            return '<a  href="' + ctx + "common/download/resource?resource=" + value + '" target="_blank">' + fileName + '</a>';
                        }else{
                            return value
                        }
                    },
                    align: 'center'
                },
                {
                    field: 'remark',
                    title: '其它要求',
                    align: 'center'
                }]
        };
        $.table.init(options);
    });
    initChildTable = function(index, row, $detail) {
        var childTable = $detail.html('<table class="table text-nowrap"></table>').find('table');
        $(childTable).bootstrapTable({
            url: ctx + "work/paper/list",
            id:'child-table',
            method: 'post',
            sidePagination: "server",
            contentType: "application/x-www-form-urlencoded",
            queryParams : {
                invoiceId: row.invoiceId
            },
            columns: [
                {
                    field: 'paperId',
                    title: '稿件ID',
                    align: 'center'
                },
                {
                    field: 'paperType',
                    title: '稿件类型',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(paperTypeDatas, value);
                    },
                    align: 'center'
                },
                {
                    field: 'paperName',
                    title: '稿件名称',
                    align: 'center'
                },
                {
                    field: 'customerName',
                    title: '客户名称',
                    align: 'center'
                },
                {
                    field: 'companyName',
                    title: '客户所属公司',
                    align: 'center'
                },
                {
                    field: 'mediaName',
                    title: '媒体名称',
                    align: 'center'
                },


                {
                    field: 'cost',
                    title: '成本',
                    align: 'center'
                },
                {
                    field: 'actualCost',
                    title: '实际成本',
                    align: 'center'
                },

                {
                    field: 'actualPrice',
                    title: '实际总价',
                    align: 'center'
                },
                {
                    field: 'priceType',
                    title: '价格类型',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(priceTypeDatas, value);
                    },
                    align: 'center'
                }]
        });
    };
    function check() {
        var ids = $.table.selectColumns('invoiceId');

        if (ids.length == 0) {
            $.modal.alertWarning("请至少选择一条记录审核");
            return;
        }
        $.modal.confirm("确认要审核选中的" + ids.length + "条数据吗?", function() {

            $.post(prefix + "/check" , {ids: ids.join()}, function (result) {

                if (result.code == web_status.SUCCESS) {
                    $.modal.msgSuccess("审核成功！")
                } else {
                    $.modal.msgError(result.msg);
                }
                $.table.refresh()
            });
        });
    }

    function grant() {
        var ids = $.table.selectColumns('invoiceId');

        if (ids.length == 0) {
            $.modal.alertWarning("请至少选择一条记录打款");
            return;
        }
        $.modal.confirm("确认要打款选中的" + ids.length + "条数据吗?", function() {

            $.post(prefix + "/grant" , {ids: ids.join()}, function (result) {

                if (result.code == web_status.SUCCESS) {
                    $.modal.msgSuccess("操作成功！")
                } else {
                    $.modal.msgError(result.msg);
                }
                $.table.refresh()
            });
        });
    }
</script>
</body>
</html>